import allure
from page_base.page_base import Base
from page_element.roncoo import *
from utils.timer import sleep

class RoncooAddMenu(Base):
    """登录页面"""
    def roncoo_login(self):
        # 打开
        self.open_url(url)
        self.maximize_window()
        with allure.step(f"输入用户名:"):
            self.send_keys(login_pe.login_username, 'admin')
        with allure.step(f"输入密码:"):
            self.send_keys(login_pe.login_pwd,'123456')
        # 强制等待输入验证码
        sleep(10)
        with allure.step("点击登录按钮"):
            self.click(login_pe.login_btn)
        #隐式等待---系统菜单
        self.driver.implicitly_wait(10)
        with allure.step('验证登录成功'):
            dy = self.text(login_pe.login_dy_text)
            print(dy)
            assert '系统菜单' in dy, f"断言失败(验证失败): 期望包含'系统菜单'，实际得到'{dy}'"
    """菜单管理添加子菜单"""
    def roncoo_add_submenu(self):
        with allure.step('点击菜单管理'):
            self.click(home_pe.menu_management)
        with allure.step('验证进入菜单管理页面'):
            dy = self.text(rightspage.menu_dy_text)
            print(dy)
            assert '菜单管理' in dy, f"断言失败(验证失败): 期望包含'系统菜单'，实际得到'{dy}'"
        with allure.step('点击权限管理菜单'):
            self.click(rightspage.menu2)
        with allure.step('点击添加菜单'):
            self.click(rightspage.add_btn)
        with allure.step('输入菜单名'):
            self.send_keys(rightspage.submenu_name, '77771')
        with allure.step('输入菜单编号'):
            self.send_keys(rightspage.submenu_num, '77771')
        with allure.step('点击保存'):
            self.click(rightspage.save_btn)
        with allure.step('点击刷新按钮'):
            self.click(rightspage.refresh_btn)
        with allure.step('点击权限管理菜单'):
            self.click(rightspage.menu2)
        with allure.step('验证过是否添加成功'):
            dy = self.text(rightspage.submenu)
            print(dy)
            assert '77771' in dy, f"断言失败(验证失败): 期望包含'系统菜单'，实际得到'{dy}'"
        with allure.step('点击新添加的菜单'):
            self.click(rightspage.submenu)
        with allure.step('点击要编辑的菜单编号'):
            self.send_keys(rightspage.edit_submenu_num,'11111')
        with allure.step('点击编辑菜单的保存按钮'):
            self.click(rightspage.edit_submenu_save_btn)
        with allure.step('验证过是否修改成功'):
            dy = self.text(rightspage.edit_submenu_num)
            print(dy)
            assert '11111' in dy, f"断言失败(验证失败): 期望包含'系统菜单'，实际得到'{dy}'"





